home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / install_list < prev    next >
Encoding:
Korn shell script  |  1995-03-24  |  3.3 KB  |  124 lines

  1. #! /bin/ksh
  2. USAGE='USAGE: install_list [ -d config_prefix ] list_file mount_path map_to_path
  3.     Each line of list_file has an inode number followed by two tabs and
  4.     a file path.  Each file path starts with the string passed in 
  5.     the mount_path argument.  The file or directory is installed
  6.     at the path formed by replacing mount_path with map_to_path.
  7.  
  8.     If a file or directory is listed and its parent directory needs
  9.     to be installed, the parent directory must be in list_file also.
  10. '
  11. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  12.  
  13. # define functions
  14.  
  15. # Process parameters
  16.  
  17.    ##echo "install_list: command: $0 $*"
  18.    CONFIG_PREFIX=""
  19.    if [ $# -ge 2 -a "$1" = "-d" ]
  20.    then
  21.       shift  # done with -d
  22.       CONFIG_PREFIX="$1"; shift
  23.    fi
  24.    if [ $# -ne 3 ]
  25.    then
  26.       echo "$USAGE" >&2
  27.       echo "$0 Expected 3 arguments, got $#" >&2
  28.       exit 1
  29.    fi
  30.    LIST_FILE="$1"; shift
  31.    if [ ! -r "$LIST_FILE" ] 
  32.    then
  33.       echo "$USAGE" >&2
  34.       echo "Unable to read list_file, $LIST_FILE" >&2
  35.       exit 1
  36.    fi
  37.    MOUNT_PATH="$1"; shift
  38.    if [ ! -d "$MOUNT_PATH" ] 
  39.    then
  40.       echo "$USAGE" >&2
  41.       echo "No directory at MOUNT_PATH, $MOUNT_PATH" >&2
  42.       exit 1
  43.    fi
  44.    MAP_TO_PATH="$1"; shift
  45.    if [ ! -d "$MAP_TO_PATH" ] 
  46.    then
  47.       echo "$USAGE" >&2
  48.       echo "No directory at MAP_TO_PATH, $MAP_TO_PATH" >&2
  49.       exit 1
  50.    fi
  51.  
  52. # Do it
  53.  
  54.  
  55.    ##echo "install_list: MOUNT_PATH is $MOUNT_PATH MAP_TO_PATH $MAP_TO_PATH"
  56.    cut -f3 "$LIST_FILE" | sort | while read FILE_PATH
  57.    do
  58.       echo "$FILE_PATH"
  59.       if [ "$FILE_PATH" = "${FILE_PATH#$MOUNT_PATH}" ]
  60.       then
  61.          if [ "$FILE_PATH" != '.' ]
  62.          then
  63.         echo "$FILE_PATH is not below $MOUNT_PATH" >&2
  64.          fi
  65.          continue
  66.       fi
  67.       if [ "$FILE_PATH" = "$MOUNT_PATH" ]
  68.       then
  69.          continue # can't install at this level
  70.       fi
  71.       if [ -d "$FILE_PATH" ]
  72.       then
  73.      FILE_DIR="$FILE_PATH"
  74.       else
  75.      FILE_DIR="$(dirname "$FILE_PATH")"
  76.       fi
  77.       if [ "$MAP_TO_PATH" = "/" ]
  78.       then
  79.      DEST_FILE="${FILE_PATH#$MOUNT_PATH}"
  80.       else
  81.      DEST_FILE="${MAP_TO_PATH}/${FILE_PATH#$MOUNT_PATH}"
  82.       fi
  83.  
  84.       ##echo "install_list: DEST_FILE is $DEST_FILE"
  85.       ##echo install_list: install_dir -d "$CONFIG_PREFIX" "$(dirname "$DEST_FILE")" "$MOUNT_PATH" "$MAP_TO_PATH"
  86.       install_dir -d "$CONFIG_PREFIX" "$(dirname "$DEST_FILE")" "$MOUNT_PATH" "$MAP_TO_PATH"
  87.       if [ -f "$FILE_PATH" ]
  88.       then
  89.          if [ -L "$DEST_FILE" ]
  90.          then
  91.         rm "$DEST_FILE"
  92.          fi
  93.          if [ -f "$DEST_FILE" ]
  94.          then
  95.             echo "$DEST_FILE is already a file"
  96.          else
  97.         cp "${FILE_PATH}" "$DEST_FILE"
  98.  
  99.         # Kludge, map in a .el when .elc is mapped in.
  100.         ##echo "install_list: FILE_PATH is '$FILE_PATH'"
  101.         if [ "$FILE_PATH" != "${FILE_PATH%.elc}" ]
  102.         then
  103.            EL_FILE="${FILE_PATH%.elc}.el"
  104.            ##echo "install_list: EL_FILE is '$EL_FILE'"
  105.            if [ -f "$EL_FILE" -a -L "${DEST_FILE%.elc}.el" ]
  106.            then
  107.               rm "${DEST_FILE%.elc}.el"
  108.               cp "$EL_FILE" "${DEST_FILE%.elc}.el"
  109.            fi
  110.         fi
  111.          fi
  112.       else
  113.          if [ ! -d "$FILE_PATH" ]
  114.          then
  115.         echo "$FILE_PATH is not a file or directory!" >&2
  116.         continue
  117.          fi
  118.          if [ -L "$DEST_FILE" ]
  119.          then
  120.         install_dir -d "$CONFIG_PREFIX" "$DEST_FILE" "$MOUNT_PATH" "$MAP_TO_PATH"
  121.          fi
  122.       fi
  123.    done
  124.